home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / usr_-_Usr_Files / BIN / PERLCC < prev    next >
Text File  |  1999-09-17  |  26KB  |  906 lines

  1. #!/usr/bin/perl
  2.     eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
  3.     if $running_under_some_shell;
  4.  
  5. use Config;
  6. use strict;
  7. use FileHandle;
  8. use File::Basename qw(&basename &dirname);
  9. use Cwd;
  10.  
  11. use Getopt::Long;
  12.  
  13. $Getopt::Long::bundling_override = 1;
  14. $Getopt::Long::passthrough = 0;
  15. $Getopt::Long::ignore_case = 0;
  16.  
  17. my $options = {};
  18. my $_fh;
  19.  
  20. main();
  21.  
  22. sub main
  23. {
  24.  
  25.     GetOptions
  26.             (
  27.             $options,   "L:s",
  28.                         "I:s",
  29.                         "C:s",
  30.                         "o:s",
  31.                         "e:s",
  32.                         "regex:s",
  33.                         "verbose:s",
  34.                         "log:s",
  35.                         "argv:s",
  36.                         "gen",
  37.                         "sav",
  38.                         "run",
  39.                         "prog",
  40.                         "mod"
  41.             );
  42.  
  43.  
  44.     my $key;
  45.  
  46.     local($") = "|";
  47.  
  48.     _usage() if (!_checkopts());
  49.     push(@ARGV, _maketempfile()) if ($options->{'e'});
  50.  
  51.     _usage() if (!@ARGV);
  52.                 
  53.     my $file;
  54.     foreach $file (@ARGV)
  55.     {
  56.         _print("
  57. --------------------------------------------------------------------------------
  58. Compiling $file:
  59. --------------------------------------------------------------------------------
  60. ", 36 );
  61.         _doit($file);
  62.     }
  63. }
  64.         
  65. sub _doit
  66. {
  67.     my ($file) = @_;
  68.  
  69.     my ($program_ext, $module_ext) = _getRegexps();
  70.     my ($obj, $objfile, $so, $type);
  71.  
  72.     if  (
  73.             (($file =~ m"@$program_ext") && ($file !~ m"@$module_ext"))
  74.             || (defined($options->{'prog'}) || defined($options->{'run'}))
  75.         )
  76.     {
  77.         $objfile = ($options->{'C'}) ?     $options->{'C'} : "$file.c";
  78.         $type = 'program';
  79.  
  80.         $obj =         ($options->{'o'})?     $options->{'o'} : 
  81.                                             _getExecutable( $file,$program_ext);
  82.  
  83.         return() if (!$obj);
  84.  
  85.     }
  86.     elsif (($file =~ m"@$module_ext") || ($options->{'mod'}))
  87.     {
  88.         die "Shared objects are not supported on Win32 yet!!!!\n"
  89.                                       if ($Config{'osname'} eq 'MSWin32');
  90.  
  91.         $obj =         ($options->{'o'})?    $options->{'o'} :
  92.                                             _getExecutable($file, $module_ext);
  93.         $so = "$obj.$Config{so}";
  94.         $type = 'sharedlib';
  95.         return() if (!$obj);
  96.         $objfile = ($options->{'C'}) ?     $options->{'C'} : "$file.c";
  97.     }
  98.     else
  99.     {
  100.         _error("noextension", $file, $program_ext, $module_ext);
  101.         return();
  102.     }
  103.  
  104.     if ($type eq 'program')
  105.     {
  106.         _print("Making C($objfile) for $file!\n", 36 );
  107.  
  108.         my $errcode = _createCode($objfile, $file);
  109.         (_print( "ERROR: In generating code for $file!\n", -1), return()) 
  110.                                                                 if ($errcode);
  111.  
  112.         _print("Compiling C($obj) for $file!\n", 36 ) if (!$options->{'gen'});
  113.         $errcode = _compileCode($file, $objfile, $obj) 
  114.                                             if (!$options->{'gen'});
  115.  
  116.         if ($errcode)
  117.         {
  118.             _print( "ERROR: In compiling code for $objfile !\n", -1);
  119.             my $ofile = File::Basename::basename($objfile);
  120.             $ofile =~ s"\.c$"\.o"s;
  121.             
  122.             _removeCode("$ofile"); 
  123.             return()
  124.         }
  125.     
  126.         _runCode($obj) if ($options->{'run'});
  127.  
  128.         _removeCode($objfile) if (!$options->{'sav'} || 
  129.                                     ($options->{'e'} && !$options->{'C'}));
  130.  
  131.         _removeCode($file) if ($options->{'e'}); 
  132.  
  133.         _removeCode($obj) if (($options->{'e'}
  134.                    && !$options->{'sav'}
  135.                    && !$options->{'o'})
  136.                   || ($options->{'run'} && !$options->{'sav'}));
  137.     }
  138.     else
  139.     {
  140.         _print( "Making C($objfile) for $file!\n", 36 );
  141.         my $errcode = _createCode($objfile, $file, $obj);
  142.         (_print( "ERROR: In generating code for $file!\n", -1), return()) 
  143.                                                                 if ($errcode);
  144.     
  145.         _print( "Compiling C($so) for $file!\n", 36 ) if (!$options->{'gen'});
  146.  
  147.         my $errorcode = 
  148.             _compileCode($file, $objfile, $obj, $so ) if (!$options->{'gen'});
  149.  
  150.         (_print( "ERROR: In compiling code for $objfile!\n", -1), return()) 
  151.                                                                 if ($errcode);
  152.     }
  153. }
  154.  
  155. sub _getExecutable
  156. {
  157.     my ($sourceprog, $ext) = @_;
  158.     my ($obj);
  159.  
  160.     if (defined($options->{'regex'}))
  161.     {
  162.         eval("(\$obj = \$sourceprog) =~ $options->{'regex'}");
  163.         return(0) if (_error('badeval', $@));
  164.         return(0) if (_error('equal', $obj, $sourceprog));
  165.     }
  166.     elsif (defined ($options->{'ext'}))
  167.     {
  168.         ($obj = $sourceprog) =~ s"@$ext"$options->{ext}"g;        
  169.         return(0) if (_error('equal', $obj, $sourceprog));
  170.     }
  171.     elsif (defined ($options->{'run'}))
  172.     {
  173.         $obj = "perlc$$";
  174.     }
  175.     else
  176.     {
  177.         ($obj = $sourceprog) =~ s"@$ext""g;
  178.         return(0) if (_error('equal', $obj, $sourceprog));
  179.     }
  180.     return($obj);
  181. }
  182.  
  183. sub _createCode
  184. {
  185.     my ( $generated_cfile, $file, $final_output ) = @_;
  186.     my $return;
  187.  
  188.     local($") = " -I";
  189.  
  190.     if (@_ == 2)                                   # compiling a program   
  191.     {
  192.         _print( "$^X -I@INC -MO=CC,-o$generated_cfile $file\n", 36);
  193.         $return =  _run("$ -I@INC -MO=CC,-o$generated_cfile $file", 9);
  194.         $return;
  195.     }
  196.     else                                           # compiling a shared object
  197.     {            
  198.         _print( 
  199.             "$ -I@INC -MO=CC,-m$final_output,-o$generated_cfile $file\n", 36);
  200.         $return = 
  201.         _run("$ -I@INC -MO=CC,-m$final_output,-o$generated_cfile $file", 9);
  202.         $return;
  203.     }
  204. }
  205.  
  206. sub _compileCode
  207. {
  208.     my ($sourceprog, $generated_cfile, $output_executable, $shared_object) = @_;
  209.     my @return;
  210.  
  211.     if (@_ == 3)                            # just compiling a program 
  212.     {
  213.         $return[0] = 
  214.         _ccharness('static', $sourceprog, "-o", $output_executable, $generated_cfile);  
  215.         $return[0];
  216.     }
  217.     else
  218.     {
  219.         my $object_file = $generated_cfile;
  220.         $object_file =~ s"\.c$"$Config{_o}";   
  221.  
  222.         $return[0] = _ccharness('compile', $sourceprog, "-c", $generated_cfile);
  223.         $return[1] = _ccharness
  224.                             (
  225.                 'dynamic', 
  226.                                 $sourceprog, "-o", 
  227.                                 $shared_object, $object_file 
  228.                             );
  229.         return(1) if (grep ($_, @return));
  230.         return(0);
  231.     }
  232. }
  233.  
  234. sub _runCode
  235. {
  236.     my ($executable) = @_;
  237.     _print("$executable $options->{'argv'}\n", 36);
  238.     _run("$executable $options->{'argv'}", -1 );
  239. }
  240.  
  241. sub _removeCode
  242. {
  243.     my ($file) = @_;
  244.     unlink($file) if (-e $file);
  245. }
  246.  
  247. sub _ccharness
  248. {
  249.     my $type = shift;
  250.     my (@args) = @_;
  251.     local($") = " ";
  252.  
  253.     my $sourceprog = shift(@args);
  254.     my ($libdir, $incdir);
  255.  
  256.     if (-d "$Config{installarchlib}/CORE")
  257.     {
  258.         $libdir = "-L$Config{installarchlib}/CORE";
  259.         $incdir = "-I$Config{installarchlib}/CORE";
  260.     }
  261.     else
  262.     {
  263.         $libdir = "-L.. -L."; 
  264.         $incdir = "-I.. -I.";
  265.     }
  266.  
  267.     $libdir .= " -L$options->{L}" if (defined($options->{L}));
  268.     $incdir .= " -I$options->{L}" if (defined($options->{L}));
  269.  
  270.     my $linkargs = '';
  271.  
  272.     if (!grep(/^-[cS]$/, @args))
  273.     {
  274.     my $lperl = $^O eq 'os2' ? '-llibperl' : '-lperl';
  275.     my $flags = $type eq 'dynamic' ? $Config{lddlflags} : $Config{ldflags};
  276.         $linkargs = "$flags $libdir $lperl @Config{libs}";
  277.     }
  278.  
  279.     my @sharedobjects = _getSharedObjects($sourceprog); 
  280.  
  281.     my $cccmd = 
  282.         "$Config{cc} @Config{qw(ccflags optimize)} $incdir @sharedobjects @args $linkargs";
  283.  
  284.  
  285.     _print ("$cccmd\n", 36);
  286.     _run("$cccmd", 18 );
  287. }
  288.  
  289. sub _getSharedObjects
  290. {
  291.     my ($sourceprog) = @_;
  292.     my ($tmpfile, $incfile);
  293.     my (@return);
  294.     local($") = " -I";
  295.  
  296.     if ($Config{'osname'} eq 'MSWin32') 
  297.     { 
  298.         # _addstuff;    
  299.     }
  300.     else
  301.     {
  302.         my ($tmpprog);
  303.         ($tmpprog = $sourceprog) =~ s"(.*)[\/\\](.*)"$2";
  304.         $tmpfile = "/tmp/$tmpprog.tst";
  305.         $incfile = "/tmp/$tmpprog.val";
  306.     }
  307.  
  308.     my $fd = new FileHandle("> $tmpfile") || die "Couldn't open $tmpfile!\n";
  309.     my $fd2 = 
  310.         new FileHandle("$sourceprog") || die "Couldn't open $sourceprog!\n";
  311.  
  312.     my $perl = <$fd2>;  # strip off header;
  313.  
  314.     print $fd 
  315. <<"EOF";
  316.         use FileHandle;
  317.         my \$fh3  = new FileHandle("> $incfile") 
  318.                                         || die "Couldn't open $incfile\\n";
  319.  
  320.         my \$key;
  321.         foreach \$key (keys(\%INC)) { print \$fh3 "\$key:\$INC{\$key}\\n"; }
  322.         close(\$fh3);
  323.         exit();
  324. EOF
  325.  
  326.     print $fd (   <$fd2>    );
  327.     close($fd);
  328.  
  329.     _print("$ -I@INC $tmpfile\n", 36);
  330.     _run("$ -I@INC $tmpfile", 9 );
  331.  
  332.     $fd = new FileHandle ("$incfile"); 
  333.     my @lines = <$fd>;    
  334.  
  335.     unlink($tmpfile);
  336.     unlink($incfile);
  337.  
  338.     my $line;
  339.     my $autolib;
  340.  
  341.     foreach $line (@lines) 
  342.     {
  343.         chomp($line);
  344.         my ($modname, $modpath) = split(':', $line);
  345.         my ($dir, $file) = ($modpath=~ m"(.*)[\\/]($modname)");
  346.         
  347.         if ($autolib = _lookforAuto($dir, $file))
  348.         {
  349.             push(@return, $autolib);
  350.         }
  351.     }
  352.  
  353.     return(@return);
  354. }
  355.  
  356. sub _maketempfile
  357. {
  358.     my $return;
  359.  
  360. #    if ($Config{'osname'} eq 'MSWin32') 
  361. #            { $return = "C:\\TEMP\\comp$$.p"; }
  362. #    else
  363. #            { $return = "/tmp/comp$$.p"; }
  364.  
  365.     $return = "comp$$.p"; 
  366.  
  367.     my $fd = new FileHandle( "> $return") || die "Couldn't open $return!\n";
  368.     print $fd $options->{'e'};
  369.     close($fd);
  370.  
  371.     return($return);
  372. }
  373.     
  374.     
  375. sub _lookforAuto
  376. {
  377.     my ($dir, $file) = @_;    
  378.  
  379.     my $relshared;
  380.     my $return;
  381.  
  382.     ($relshared = $file) =~ s"(.*)\.pm"$1";
  383.  
  384.     my ($tmp, $modname) = ($relshared =~ m"(?:(.*)[\\/]){0,1}(.*)"s);
  385.  
  386.     $relshared .= 
  387.         ($Config{'osname'} eq 'MSWin32')? "\\$modname.dll" : "/$modname.so";
  388.     
  389.  
  390.  
  391.     if (-e ($return = "$Config{'installarchlib'}/auto/$relshared") )
  392.     {
  393.         return($return);    
  394.     }
  395.     elsif (-e ($return = "$Config{'installsitearch'}/auto/$relshared"))
  396.     {
  397.         return($return);
  398.     }
  399.     elsif (-e ($return = "$dir/arch/auto/$relshared"))
  400.     {
  401.         return($return);    
  402.     }
  403.     else
  404.     {
  405.         return(undef);
  406.     }
  407. }
  408.  
  409. sub _getRegexps    # make the appropriate regexps for making executables, 
  410. {                  # shared libs
  411.  
  412.     my ($program_ext, $module_ext) = ([],[]); 
  413.  
  414.  
  415.     @$program_ext = ($ENV{PERL_SCRIPT_EXT})? split(':', $ENV{PERL_SCRIPT_EXT}) :
  416.                                             ('.p$', '.pl$', '.bat$');
  417.  
  418.  
  419.     @$module_ext  = ($ENV{PERL_MODULE_EXT})? split(':', $ENV{PERL_MODULE_EXT}) :
  420.                                             ('.pm$');
  421.  
  422.  
  423.     _mungeRegexp( $program_ext );
  424.     _mungeRegexp( $module_ext  );    
  425.  
  426.     return($program_ext, $module_ext);
  427. }
  428.  
  429. sub _mungeRegexp
  430. {
  431.     my ($regexp) = @_;
  432.  
  433.     grep(s:(^|[^\\])\.:$1\x00\\.:g, @$regexp);
  434.     grep(s:(^|[^\x00])\\\.:$1\.:g,  @$regexp);
  435.     grep(s:\x00::g,                 @$regexp);
  436. }
  437.  
  438.  
  439. sub _error
  440. {
  441.     my ($type, @args) = @_;
  442.  
  443.     if ($type eq 'equal')
  444.     {
  445.             
  446.         if ($args[0] eq $args[1])
  447.         {
  448.             _print ("ERROR: The object file '$args[0]' does not generate a legitimate executable file! Skipping!\n", -1);
  449.             return(1);
  450.         }
  451.     }
  452.     elsif ($type eq 'badeval')
  453.     {
  454.         if ($args[0])
  455.         {
  456.             _print ("ERROR: $args[0]\n", -1);
  457.             return(1);
  458.         }
  459.     }
  460.     elsif ($type eq 'noextension')
  461.     {
  462.         my $progext = join(',', @{$args[1]});
  463.         my $modext  = join(',', @{$args[2]});
  464.  
  465.         $progext =~ s"\\""g;
  466.         $modext  =~ s"\\""g;
  467.  
  468.         $progext =~ s"\$""g;
  469.         $modext  =~ s"\$""g;
  470.  
  471.         _print 
  472.         (
  473. "
  474. ERROR: '$args[0]' does not have a proper extension! Proper extensions are:
  475.  
  476.     PROGRAM:       $progext 
  477.     SHARED OBJECT: $modext
  478.  
  479. Use the '-prog' flag to force your files to be interpreted as programs.
  480. Use the '-mod' flag to force your files to be interpreted as modules.
  481. ", -1
  482.         );
  483.         return(1);
  484.     }
  485.  
  486.     return(0);
  487. }
  488.  
  489. sub _checkopts
  490. {
  491.     my @errors;
  492.     local($") = "\n";
  493.  
  494.     if ($options->{'log'})
  495.     {
  496.         $_fh = new FileHandle(">> $options->{'log'}") || push(@errors, "ERROR: Couldn't open $options->{'log'}\n");
  497.     }
  498.  
  499.     if (($options->{'c'}) && (@ARGV > 1) && ($options->{'sav'} ))
  500.     {
  501.         push(@errors, 
  502. "ERROR: The '-sav' and '-C' options are incompatible when you have more than 
  503.        one input file! ('-C' explicitly names resulting C code, '-sav' saves it,
  504.        and hence, with more than one file, the c code will be overwritten for 
  505.        each file that you compile)\n");
  506.     }
  507.     if (($options->{'o'}) && (@ARGV > 1))
  508.     {
  509.         push(@errors, 
  510. "ERROR: The '-o' option is incompatible when you have more than one input file! 
  511.        (-o explicitly names the resulting executable, hence, with more than 
  512.        one file the names clash)\n");
  513.     }
  514.  
  515.     if ($options->{'e'} && $options->{'sav'} && !$options->{'o'} && 
  516.                                                             !$options->{'C'})
  517.     {
  518.         push(@errors, 
  519. "ERROR: You need to specify where you are going to save the resulting 
  520.        executable or C code,  when using '-sav' and '-e'. Use '-o' or '-C'.\n");
  521.     }
  522.  
  523.     if (($options->{'regex'} || $options->{'run'} || $options->{'o'}) 
  524.                                                     && $options->{'gen'})
  525.     {
  526.         push(@errors, 
  527. "ERROR: The options '-regex', '-run', and '-o' are incompatible with '-gen'. 
  528.        '-gen' says to stop at C generation, and the other three modify the 
  529.        compilation and/or running process!\n");
  530.     }
  531.  
  532.     if ($options->{'run'} && $options->{'mod'})
  533.     {
  534.         push(@errors, 
  535. "ERROR: Can't run modules that you are compiling! '-run' and '-mod' are 
  536.        incompatible!\n"); 
  537.     }
  538.  
  539.     if ($options->{'e'} && @ARGV)
  540.     {
  541.         push (@errors, 
  542. "ERROR: The option '-e' needs to be all by itself without any other 
  543.        file arguments!\n");
  544.     }
  545.     if ($options->{'e'} && !($options->{'o'} || $options->{'run'}))
  546.     {
  547.         $options->{'run'} = 1;
  548.     }
  549.  
  550.     if (!defined($options->{'verbose'})) 
  551.     { 
  552.         $options->{'verbose'} = ($options->{'log'})? 64 : 7; 
  553.     }
  554.  
  555.     my $verbose_error;
  556.  
  557.     if ($options->{'verbose'} =~ m"[^tagfcd]" && 
  558.             !( $options->{'verbose'} eq '0' || 
  559.                 ($options->{'verbose'} < 64 && $options->{'verbose'} > 0)))
  560.     {
  561.         $verbose_error = 1;
  562.         push(@errors, 
  563. "ERROR: Illegal verbosity level.  Needs to have either the letters 
  564.        't','a','g','f','c', or 'd' in it or be between 0 and 63, inclusive.\n");
  565.     }
  566.  
  567.     $options->{'verbose'} = ($options->{'verbose'} =~ m"[tagfcd]")? 
  568.                             ($options->{'verbose'} =~ m"d") * 32 +     
  569.                             ($options->{'verbose'} =~ m"c") * 16 +     
  570.                             ($options->{'verbose'} =~ m"f") * 8     +     
  571.                             ($options->{'verbose'} =~ m"t") * 4     +     
  572.                             ($options->{'verbose'} =~ m"a") * 2     +     
  573.                             ($options->{'verbose'} =~ m"g") * 1     
  574.                                                     : $options->{'verbose'};
  575.  
  576.     if     (!$verbose_error && (    $options->{'log'} && 
  577.                                 !(
  578.                                     ($options->{'verbose'} & 8)   || 
  579.                                     ($options->{'verbose'} & 16)  || 
  580.                                     ($options->{'verbose'} & 32 ) 
  581.                                 )
  582.                             )
  583.         )
  584.     {
  585.         push(@errors, 
  586. "ERROR: The verbosity level '$options->{'verbose'}' does not output anything 
  587.        to a logfile, and you specified '-log'!\n");
  588.     } # }
  589.  
  590.     if     (!$verbose_error && (    !$options->{'log'} && 
  591.                                 (
  592.                                     ($options->{'verbose'} & 8)   || 
  593.                                     ($options->{'verbose'} & 16)  || 
  594.                                     ($options->{'verbose'} & 32)  || 
  595.                                     ($options->{'verbose'} & 64)
  596.                                 )
  597.                             )
  598.         )
  599.     {
  600.         push(@errors, 
  601. "ERROR: The verbosity level '$options->{'verbose'}' requires that you also 
  602.        specify a logfile via '-log'\n");
  603.     } # }
  604.  
  605.  
  606.     (_print( "\n". join("\n", @errors), -1), return(0)) if (@errors);
  607.     return(1);
  608. }
  609.  
  610. sub _print
  611. {
  612.     my ($text, $flag ) = @_;
  613.     
  614.     my $logflag = int($flag/8) * 8;
  615.     my $regflag = $flag % 8;
  616.  
  617.     if ($flag == -1 || ($flag & $options->{'verbose'}))
  618.     {
  619.         my $dolog = ((($logflag & $options->{'verbose'}) || $flag == -1) 
  620.                                                         && $options->{'log'}); 
  621.  
  622.         my $doreg = (($regflag & $options->{'verbose'}) || $flag == -1);
  623.         
  624.         if ($doreg) { print( STDERR $text ); }
  625.         if ($dolog) { print $_fh $text; }
  626.     }
  627. }
  628.  
  629. sub _run
  630. {
  631.     my ($command, $flag) = @_;
  632.  
  633.     my $logflag = ($flag != -1)? int($flag/8) * 8 : 0;
  634.     my $regflag = $flag % 8;
  635.  
  636.     if ($flag == -1 || ($flag & $options->{'verbose'}))
  637.     {
  638.         my $dolog = ($logflag & $options->{'verbose'} && $options->{'log'});
  639.         my $doreg = (($regflag & $options->{'verbose'}) || $flag == -1);
  640.  
  641.         if ($doreg && !$dolog) 
  642.             { system("$command"); }
  643.  
  644.         elsif ($doreg && $dolog) 
  645.             { my $text = `$command 2>&1`; print $_fh $text; print STDERR $text;}
  646.         else 
  647.             { my $text = `$command 2>&1`; print $_fh $text; }
  648.     }
  649.     else 
  650.     {
  651.         `$command 2>&1`; 
  652.     }
  653.     return($?);
  654. }
  655.  
  656. sub _usage
  657. {
  658.     _print
  659.     ( 
  660.     <<"EOF"
  661.  
  662. Usage: $0 <file_list> 
  663.  
  664.     Flags with arguments
  665.         -L       < extra library dirs for installation (form of 'dir1:dir2') >
  666.         -I       < extra include dirs for installation (form of 'dir1:dir2') >
  667.         -C       < explicit name of resulting C code > 
  668.         -o       < explicit name of resulting executable >
  669.         -e       < to compile 'one liners'. Need executable name (-o) or '-run'>
  670.         -regex   < rename regex, -regex 's/\.p/\.exe/' compiles a.p to a.exe >
  671.         -verbose < verbose level (1-63, or following letters 'gatfcd' >
  672.         -argv    < arguments for the executables to be run via '-run' or '-e' > 
  673.  
  674.     Boolean flags
  675.         -gen     ( to just generate the c code. Implies '-sav' )
  676.         -sav     ( to save intermediate c code, (and executables with '-run'))
  677.         -run     ( to run the compiled program on the fly, as were interpreted.)
  678.         -prog    ( to indicate that the files on command line are programs )
  679.         -mod     ( to indicate that the files on command line are modules  )
  680.  
  681. EOF
  682. , -1
  683.  
  684.     );
  685.     exit(255);
  686. }
  687.  
  688.  
  689. __END__
  690.  
  691. =head1 NAME
  692.  
  693. perlcc - frontend for perl compiler
  694.  
  695. =head1 SYNOPSIS
  696.  
  697.     %prompt  perlcc a.p        # compiles into executable 'a'
  698.  
  699.     %prompt  perlcc A.pm       # compile into 'A.so'
  700.  
  701.     %prompt  perlcc a.p -o execute  # compiles 'a.p' into 'execute'.
  702.  
  703.     %prompt  perlcc a.p -o execute -run # compiles 'a.p' into execute, runs on
  704.                                         # the fly
  705.  
  706.     %prompt  perlcc a.p -o execute -run -argv 'arg1 arg2 arg3' 
  707.                                         # compiles into execute, runs with 
  708.                                         # arg1 arg2 arg3 as @ARGV
  709.  
  710.     %prompt perlcc a.p b.p c.p -regex 's/\.p/\.exe'
  711.                                         # compiles into 'a.exe','b.exe','c.exe'.
  712.  
  713.     %prompt perlcc a.p -log compilelog  # compiles into 'a', saves compilation
  714.                                         # info into compilelog, as well
  715.                                         # as mirroring to screen
  716.  
  717.     %prompt perlcc a.p -log compilelog -verbose cdf 
  718.                                         # compiles into 'a', saves compilation
  719.                                         # info into compilelog, being silent
  720.                                         # on screen.
  721.  
  722.     %prompt perlcc a.p -C a.c -gen      # generates C code (into a.c) and 
  723.                                         # stops without compile.
  724.  
  725.     %prompt perlcc a.p -L ../lib a.c 
  726.                                         # Compiles with the perl libraries 
  727.                                         # inside ../lib included.
  728.  
  729. =head1 DESCRIPTION
  730.  
  731. 'perlcc' is the frontend into the perl compiler. Typing 'perlcc a.p'
  732. compiles the code inside a.p into a standalone executable, and 
  733. perlcc A.pm will compile into a shared object, A.so, suitable for inclusion 
  734. into a perl program via "use A".
  735.  
  736. There are quite a few flags to perlcc which help with such issues as compiling 
  737. programs in bulk, testing compiled programs for compatibility with the 
  738. interpreter, and controlling.
  739.  
  740. =head1 OPTIONS 
  741.  
  742. =over 4
  743.  
  744. =item -L < library_directories >
  745.  
  746. Adds directories in B<library_directories> to the compilation command.
  747.  
  748. =item -I  < include_directories > 
  749.  
  750. Adds directories inside B<include_directories> to the compilation command.
  751.  
  752. =item -C   < c_code_name > 
  753.  
  754. Explicitly gives the name B<c_code_name> to the generated c code which is to 
  755. be compiled. Can only be used if compiling one file on the command line.
  756.  
  757. =item -o   < executable_name >
  758.  
  759. Explicitly gives the name B<executable_name> to the executable which is to be
  760. compiled. Can only be used if compiling one file on the command line.
  761.  
  762. =item -e   < perl_line_to_execute>
  763.  
  764. Compiles 'one liners', in the same way that B<perl -e> runs text strings at 
  765. the command line. Default is to have the 'one liner' be compiled, and run all
  766. in one go (see B<-run>); giving the B<-o> flag saves the resultant executable, 
  767. rather than throwing it away. Use '-argv' to pass arguments to the executable
  768. created.
  769.  
  770. =item -regex   <rename_regex>
  771.  
  772. Gives a rule B<rename_regex> - which is a legal perl regular expression - to 
  773. create executable file names.
  774.  
  775. =item -verbose <verbose_level>
  776.  
  777. Show exactly what steps perlcc is taking to compile your code. You can change 
  778. the verbosity level B<verbose_level> much in the same way that the '-D' switch 
  779. changes perl's debugging level, by giving either a number which is the sum of 
  780. bits you want or a list of letters representing what you wish to see. Here are 
  781. the verbosity levels so far :
  782.  
  783.     Bit 1(g):      Code Generation Errors to STDERR
  784.     Bit 2(a):      Compilation Errors to STDERR
  785.     Bit 4(t):      Descriptive text to STDERR 
  786.     Bit 8(f):      Code Generation Errors to file (B<-log> flag needed)
  787.     Bit 16(c):     Compilation Errors to file (B<-log> flag needed)
  788.     Bit 32(d):     Descriptive text to file (B<-log> flag needed) 
  789.  
  790. If the B<-log> tag is given, the default verbose level is 63 (ie: mirroring 
  791. all of perlcc's output to both the screen and to a log file). If no B<-log>
  792. tag is given, then the default verbose level is 7 (ie: outputting all of 
  793. perlcc's output to STDERR).
  794.  
  795. NOTE: Because of buffering concerns, you CANNOT shadow the output of '-run' to
  796. both a file, and to the screen! Suggestions are welcome on how to overcome this
  797. difficulty, but for now it simply does not work properly, and hence will only go
  798. to the screen.
  799.  
  800. =item -log <logname>
  801.  
  802. Opens, for append, a logfile to save some or all of the text for a given 
  803. compile command. No rewrite version is available, so this needs to be done 
  804. manually.
  805.  
  806. =item -argv <arguments>
  807.  
  808. In combination with '-run' or '-e', tells perlcc to run the resulting 
  809. executable with the string B<arguments> as @ARGV.
  810.  
  811. =item -sav
  812.  
  813. Tells perl to save the intermediate C code. Usually, this C code is the name
  814. of the perl code, plus '.c'; 'perlcode.p' gets generated in 'perlcode.p.c',
  815. for example. If used with the '-e' operator, you need to tell perlcc where to 
  816. save resulting executables.
  817.  
  818. =item -gen
  819.  
  820. Tells perlcc to only create the intermediate C code, and not compile the 
  821. results. Does an implicit B<-sav>, saving the C code rather than deleting it.
  822.  
  823. =item -run
  824.  
  825. Immediately run the perl code that has been generated. NOTE: IF YOU GIVE THE 
  826. B<-run> FLAG TO B<perlcc>, THEN THE REST OF @ARGV WILL BE INTERPRETED AS 
  827. ARGUMENTS TO THE PROGRAM THAT YOU ARE COMPILING.
  828.  
  829. =item -prog
  830.  
  831. Indicate that the programs at the command line are programs, and should be
  832. compiled as such. B<perlcc> will automatically determine files to be 
  833. programs if they have B<.p>, B<.pl>, B<.bat> extensions.
  834.  
  835. =item -mod
  836.  
  837. Indicate that the programs at the command line are modules, and should be
  838. compiled as such. B<perlcc> will automatically determine files to be 
  839. modules if they have the extension B<.pm>.
  840.  
  841. =back
  842.  
  843. =head1 ENVIRONMENT
  844.  
  845. Most of the work of B<perlcc> is done at the command line. However, you can 
  846. change the heuristic which determines what is a module and what is a program.
  847. As indicated above, B<perlcc> assumes that the extensions:
  848.  
  849. .p$, .pl$, and .bat$
  850.  
  851. indicate a perl program, and:
  852.  
  853. .pm$
  854.  
  855. indicate a library, for the purposes of creating executables. And furthermore,
  856. by default, these extensions will be replaced (and dropped ) in the process of 
  857. creating an executable. 
  858.  
  859. To change the extensions which are programs, and which are modules, set the
  860. environmental variables:
  861.  
  862. PERL_SCRIPT_EXT
  863. PERL_MODULE_EXT
  864.  
  865. These two environmental variables take colon-separated, legal perl regular 
  866. expressions, and are used by perlcc to decide which objects are which. 
  867. For example:
  868.  
  869. setenv PERL_SCRIPT_EXT  '.prl$:.perl$'
  870. prompt%   perlcc sample.perl
  871.  
  872. will compile the script 'sample.perl' into the executable 'sample', and
  873.  
  874. setenv PERL_MODULE_EXT  '.perlmod$:.perlmodule$'
  875.  
  876. prompt%   perlcc sample.perlmod
  877.  
  878. will  compile the module 'sample.perlmod' into the shared object 
  879. 'sample.so'
  880.  
  881. NOTE: the '.' in the regular expressions for PERL_SCRIPT_EXT and PERL_MODULE_EXT
  882. is a literal '.', and not a wild-card. To get a true wild-card, you need to 
  883. backslash the '.'; as in:
  884.  
  885. setenv PERL_SCRIPT_EXT '\.\.\.\.\.'
  886.  
  887. which would have the effect of compiling ANYTHING (except what is in 
  888. PERL_MODULE_EXT) into an executable with 5 less characters in its name.
  889.  
  890. =head1 FILES
  891.  
  892. 'perlcc' uses a temporary file when you use the B<-e> option to evaluate 
  893. text and compile it. This temporary file is 'perlc$$.p'. The temporary C code is
  894. perlc$$.p.c, and the temporary executable is perlc$$.
  895.  
  896. When you use '-run' and don't save your executable, the temporary executable is
  897. perlc$$
  898.  
  899. =head1 BUGS
  900.  
  901. perlcc currently cannot compile shared objects on Win32. This should be fixed
  902. by perl5.005.
  903.  
  904. =cut
  905.  
  906.